package com.acme.service;

import java.util.List;

import com.acme.domain.account.Account;
import com.acme.domain.bank.Bank;
import com.acme.domain.client.Client;
import com.acme.exceptions.ClientExistsException;
import com.acme.exceptions.NotEnoughFundsException;

public class BankService
{
	public static void addClient(final Bank curBank, final Client newClient)
		throws ClientExistsException
	{
		curBank.addClient(newClient);
	}
	
	public static void depositToAll(final Bank curBank, final double amount)
		throws IllegalArgumentException
	{
		Client[] curClients = curBank.getClients();
		for (int i = 0; i < curBank.getBankSize(); i++)
		{
			List<Account> curClientAccounts = curClients[i].getAccountsList();
			for (Account acc : curClientAccounts)
			{
				acc.deposit(amount);
			}
		}
	}
	
	public static void withdrawFromSmb(final Bank curBank, final int id,
		final double amount)
			throws IllegalArgumentException, NotEnoughFundsException
	{
		Client[] curClients = curBank.getClients();
		for (int i = 0; i < curBank.getBankSize(); i++)
		{
			List<Account> curClientAccounts = curClients[i].getAccountsList();
			for (Account acc : curClientAccounts)
			{
				if(acc.getID() == id)
				{
					acc.withdraw(amount);
				}
			}
		}
	}
}
